package cn.qu.netty.boot.example.filter;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import cn.qu.netty.boot.Bean;
import cn.qu.netty.boot.CheckIpInboundHandler;
import cn.qu.netty.boot.Log;
import cn.qu.netty.boot.OncePerRequestFilter;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.util.CharsetUtil;

@Bean
public class PrintFilter implements OncePerRequestFilter {

	final static Log log = Log.createLog();
	
	@Override
	public void doFilter(FullHttpRequest req) {
		String ip = req.headers().get(CheckIpInboundHandler.CHECK_IP_HEADER);
		try {
			log.log("来自" + ip + "的访问：" + URLDecoder.decode(req.uri(), CharsetUtil.UTF_8.name()));
		} catch (UnsupportedEncodingException e) {
		}
	}

}
